<?php
/**
 * Description of Project
 * @author XPS-15
 */
require_once("defs/Constants.php");
require_once(FILE_DB_CONTROLE);
require_once(FILE_DB_PROJECT);

class Project {
    
    private $id = '';
    private $naam = '';
    private $locatie = '';
    private $leidinggevende = '';
    private $database = '';
    private $controle = '';
    private $error_count = '';
    
    function __construct($dataArray) {
        $this->controle = new DbControle();
        $this->database = new DbProject('');
        $this->setNaam($dataArray['naam_project']);
        $this->setLocatie($dataArray['locatie']);
        $this->setLeidinggevende($dataArray['leidinggevende']);
    }
    
    public function save(){
        $this->database->save($this->naam, $this->locatie, $this->leidinggevende);
    }

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        if($this->controle->checkId($id)){
            $this->id = $id;
        }else{
            throw Exception("ID incorrect");
        }
    }
    
    public function getNaam() {
        return $this->naam;
    }

    public function setNaam($naam) {
        if ($this->controle->checkString($naam, DB_NUMBER_COMON_MAXIMUM, MINIMUM_ALGEMEEN)) {
            $this->naam = $naam;
        } else {
            $this->error_count++;
            echo WHITE_SPACE_ENTER;
            echo PERSOON_ERROR_GEENNAAM;
        }
    }

    public function getLocatie() {
        return $this->locatie;
    }

    public function setLocatie($locatie) {
        if ($this->controle->checkString($locatie, DB_NUMBER_COMON_MAXIMUM, MINIMUM_ALGEMEEN)) {
            $this->locatie = $locatie;
        } else {
            $this->error_count++;
            echo WHITE_SPACE_ENTER;
            echo VOER_EEN_GELDIGE_LOCATIE_IN;
        }
    }

    public function getLeidinggevende() {
        return $this->leidinggevende;
    }

    public function setLeidinggevende($leidinggevende) {
        if ($this->controle->checkString($leidinggevende, DB_NUMBER_COMON_MAXIMUM, MINIMUM_ALGEMEEN)) {
            $this->leidinggevende = $leidinggevende;
        } else {
            $this->error_count++;
            echo WHITE_SPACE_ENTER;
            echo VOER_EEN_GELDIGE_LOCATIE_IN;
        }  
    }
    
    public function checkError() {
        if($this->error_count != 0) {
            echo WHITE_SPACE_ENTER;
            echo GUI_FOUTEN_GEVONDEN_ERROR;
        } else {
            echo WHITE_SPACE_ENTER;
            echo GUI_GEEN_FOUTEN_GEVONDEN_ERROR;
            $new = new Project();
            $new->save();
        }
    }
    
}

?>
